package com.syg.servlet06_JspApplication;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Calculator.jsp")
public class _02_ServletForward extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String firstNum = req.getParameter("firstNum");
        String operator = req.getParameter("operator");
        String secondNum = req.getParameter("secondNum");
        _01_CalculatorBean calculatorBean = new _01_CalculatorBean();
        if (!(null==secondNum&&null==firstNum)){
            calculatorBean.setFirstNum(Double.parseDouble(firstNum));
            calculatorBean.setOperator(operator.charAt(0));
            calculatorBean.setSecondNum(Double.parseDouble(secondNum));
        }
        req.getRequestDispatcher("\\WEB-INF\\JspPage\\servlet06_JspApplication\\Calculator.jsp").forward(req,resp);
    }
}
